/**
 * @author Caius
 * @description
 *      定义股票的相关接口控制器
 * @version 1.0
 * @since Created in 2025-01-03
 */

package com.itsense.stock.controller;

import com.itsense.stock.mapper.StockRtInfoMapper;
import com.itsense.stock.pojo.domain.*;
import com.itsense.stock.service.StockService;
import com.itsense.stock.vo.resp.PageResult;
import com.itsense.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api("/api/quot")
@RestController
@RequestMapping("/api/quot")
public class StockController {
    @Autowired
    private StockService stockService;
    @Autowired
    private StockRtInfoMapper stockRtInfoMapper;

    /**
     * 获取国内大盘的最新数据
     * @return
     */
    @ApiOperation(value = "获取国内大盘的最新数据", notes = "获取国内大盘的最新数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo(){
        return stockService.getInnerMarketInfo();
    }

    /**
     * 获取国外大盘的最新数据
     * @return
     */
    @ApiOperation(value = "获取国外大盘的最新数据", notes = "获取国外大盘的最新数据", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> getOuterMarketInfo(){
        return stockService.getOuterMarketInfo();
    }

    /**
     * 获取深沪实时模块值
     * @return
     */
    @ApiOperation(value = "获取深沪实时模块值", notes = "获取深沪实时模块值", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getStockBlockInfo(){
        return stockService.getStockBlockInfo();
    }

    /**
     * 分页查询最新的股票交易数据
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "分页查询最新的股票交易数据", notes = "分页查询最新的股票交易数据", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<StockUpDownDomain>> getStockInfoByPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize){

        return stockService.getStockInfoByPage(page, pageSize);
    }

    /**
     * 获取股票最新交易数据的前面四项
     * @return
     */
    @ApiOperation(value = "获取股票最新交易数据的前面四项", notes = "获取股票最新交易数据的前面四项", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpDownDomain>> getStockInfoIncrease(){
        return stockService.getStockInfoIncrease();
    }

    /**
     * 获取最新涨跌股票信息
     * @return
     */
    @ApiOperation(value = "获取最新涨跌股票信息", notes = "获取最新涨跌股票信息", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String, List>> getStockUpDownCount(){
        return stockService.getStockUpDownCount();
    }

    /**
     * 导出指定页码的最新股票信息
     * @param page
     * @param pageSize
     * @param response
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "导出指定页码的最新股票信息", notes = "导出指定页码的最新股票信息", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void exportStockUpDownInfo(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                      @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                      HttpServletResponse response){

         stockService.exportStockUpDownInfo(page, pageSize, response);
    }

    /**
     * 返回T日和T-1日的每分钟交易量的统计
     * @return
     */
    @ApiOperation(value = "返回T日和T-1日的每分钟交易量的统计", notes = "返回T日和T-1日的每分钟交易量的统计", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String, List>> getComparedStockTradeAmt(){
        return stockService.getComparedStockTradeAmt();
    }

    /**
     * 获取股票的每日涨幅范围数据(A股)
     * @return
     */
    @ApiOperation(value = "获取股票的每日涨幅范围数据(A股)", notes = "获取股票的每日涨幅范围数据(A股)", httpMethod = "GET")
    @GetMapping("stock/updown")
    public R<Map> getIncreaseRangeInfo(){
        return stockService.getIncreaseRangeInfo();
    }

    /**
     * 获取指定股票的T日的分时数据
     * @param stockCode
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "获取指定股票的T日的分时数据", notes = "获取指定股票的T日的分时数据", httpMethod = "GET")
    @GetMapping("stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenTimeSharing(stockCode);
    }

    /**
     * 统计指定股票的日K数据
     * @param stockCode
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "统计指定股票的日K数据", notes = "统计指定股票的日K数据", httpMethod = "GET")
    @GetMapping("stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDKLine(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenDKLine(stockCode);
    }

    /**
     * 返回模糊搜索股票信息
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "searchStr", value = "", required = true)
    })
    @ApiOperation(value = "返回模糊搜索股票信息", notes = "返回模糊搜索股票信息", httpMethod = "GET")
    @GetMapping("stock/search")
    public R<List<StockSearchResultDomain>> getStockSearchResult(@RequestParam(value = "searchStr", required = true) String searchStr){
        return stockService.getStockSearchResult(searchStr);
    }

    /**
     * 通过股票编码返回对应的股票主营业务数据
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "通过股票编码返回对应的股票主营业务数据", notes = "通过股票编码返回对应的股票主营业务数据", httpMethod = "GET")
    @GetMapping("stock/describe")
    public R<StockDescribeDomain> getStockDescribe(@RequestParam(value = "code", required = true) String code){
        return stockService.getStockDescribe(code);
    }

    /**
     * 通过股票编码返回对应的周K线
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "通过股票编码返回对应的周K线", notes = "通过股票编码返回对应的周K线", httpMethod = "GET")
    @GetMapping("stock/screen/weekkline")
    public R<List<Stock4EvrWeekDomain>> getStockScreenWKLine(@RequestParam(value = "code") String code){
        return stockService.getStockWKLine(code);
    }

    /**
     * 通过股票编码返回对应的股票实时数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "通过股票编码返回对应的股票实时数据", notes = "通过股票编码返回对应的股票实时数据", httpMethod = "GET")
    @GetMapping("stock/screen/second/detail")
    private R<StockRt> getStockScreenRtInfo(@RequestParam(value = "code") String code){
        return stockService.getStockScreenRtInfo(code);
    }

    /**
     * 通过股票编码返回个股行情数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "通过股票编码返回个股行情数据", notes = "通过股票编码返回个股行情数据", httpMethod = "GET")
    @GetMapping("stock/screen/second")
    public R<List<Map<String,Object>>>getStockTradeInStatement(@RequestParam("code")String code){
        return stockService.getStockTradeInStatement(code);
    }
}
